#include <Rectangle.h>

Rectangle::Rectangle(unsigned int width, unsigned int height)
{
	if(isValid(width,height))
	{
		width_m = static_cast < float > width;
		height_m = static_cast < float > height;
	}
	
	width_m = convertPrecision(width_m);
	height_m = convertPrecision(height_m);

	area = width * height;
	perimeter = 2 * (width + height);
	
	area = convertPrecision(area);
	perimeter = convertPrecision(perimeter);
}

Rectangle::Rectangle(float width, float height):width_m(width),height_m(height)
{
	isValid(width,height);

	width_m = convertPrecision(width_m);
	height_m = convertPrecision(height_m);

	area = width * height;
	perimeter = 2 * (width + height);

	area = convertPrecision(area);
	perimeter = convertPrecision(perimeter);
}

Rectangle::Rectangle(unsigned int width, float height):height_m(height)
{
	if(isValid(width,height))
	{
		width_m = static_cast < float > width;
	}

	width_m = convertPrecision(width_m);
	height_m = convertPrecision(height_m);

	area = width * height;
	perimeter = 2 * (width + height);

	area = convertPrecision(area);
	perimeter = convertPrecision(perimeter);
}

Rectangle::Rectangle(float width, unsigned int height):width_m(width)
{
	if(isValid(width,height))
	{
		height_m = static_cast < float > height;
	}

	width_m = convertPrecision(width_m);
	height_m = convertPrecision(height_m);

	area = width * height;
	perimeter = 2 * (width + height);

	area = convertPrecision(area);
	perimeter = convertPrecision(perimeter);
}

Rectangle::Rectangle(unsigned int side)
{
	if(isValid(width,height))
	{
		width_m = static_cast < float > side;
		height_m = static_cast < float > side;
	}
	width_m = convertPrecision(width_m);
	height_m = convertPrecision(height_m);

	area = width * height;
	perimeter = 2 * (width + height);

	area = convertPrecision(area);
	perimeter = convertPrecision(perimeter);
}

Rectangle::Rectangle(float side):width_m(side),height_m(side)
{
	isValid(width,height);

	width_m = convertPrecision(width_m);
	height_m = convertPrecision(height_m);

	area = width * height;
	perimeter = 2 * (width + height);

	area = convertPrecision(area);
	perimeter = convertPrecision(perimeter);
}

bool Rectangle::isValid(unsigned int width, unsigned int height)
{	
	bool retValue = true;
	if(width < 0 || width > 100)
	{
		width_m = 0.0;
		retValue = false;
	}
	if(height < 0.0 || height > 100.0)
	{	
		height_m = 0.0;
		retValue = false;
	}
	return retValue;

}
bool Rectangle::isValid(float width, float height)
{
	bool retValue = true;
	if(height < 0.0 || height > 100.0)
	{
		height_m = 0.0;
		retValue = false;
	}
	if(width < 0.0 || width > 100.0)
	{	
		width_m = 0.0;
		retValue = false;
	}
	return retValue;
}
bool Rectangle::isValid(float width, unsigned int height)
{
	bool retValue = true;
	if(height < 0 || height > 100)
	{
		height_m = 0.0;
		retValue = false;
	}
	if(width < 0.0 || width > 100.0)
	{	
		width_m = 0.0;
		retValue = false;
	}
	return retValue;
}
bool Rectangle::isValid(unsigned int width, float height)
{
	bool retValue = true;
	if(height < 0.0 || height > 100.0)
	{
		height_m = 0.0;
		retValue = false;
	}
	if(width < 0 || width > 100)
	{	
		width_m = 0.0;
		retValue = false;
	}
	return retValue;
}

void Rectangle::setWidth(unsigned int width)
{

	if(width > 100)
	{
		width_m = 100.0;
	}
	else
	{
		width_m = static_cast < float > width;
	}
	
}
void Rectangle::setWidth(float width)
{
	if(width > 100.0)
		width_m = 100.0;
	if(width < 0.0)
	{
		return;
	}
	else
	{
		width_m = width;
	}
}
void Rectangle::setHeight(unsigned int height)
{
	if(height > 100)
	{
		height_m = 100.0;
	}
	else
	{
		height_m = static_cast < float > height;
	}
}
void Rectangle::setHeigth(float height)
{
	if(height > 100.0)
		height_m = 100.0;
	if(height < 0.0)
	{
		return;
	}
	else
	{
		height_m = height;
	}
}

float Rectangle::convertPrecision(float value) const
{
	int temp;
	temp = static_cast < int >  value * 100;
	return temp/100.00
}

float Rectangle::getArea() const
{
	return area;
}

float Rectangle::getPerimeter() const
{
	return perimeter;
}
